<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">


    <title> - 用户列表</title>
    <meta content="" name="keywords">
    <meta content="" name="description">

    <link href="favicon.ico" rel="shortcut icon">
    <link href="/static/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <!--<link href="/static/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">-->
    <link href="/static/hAdmin/css/style.css?version4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <style>
        .addList {
            padding: 10px 30px 10px 30px;
            height: 90px;
            margin-top: 3px
        }
    </style>

</head>

<body class="gray-bg">
<div id="block"
     style="width: 100%;height: 100%;background: #171717;opacity: 0.7;position: fixed;top: 0;left: 0;z-index: 999;text-align: center;display: none">
    <div style="margin-top: 300px">
        <span style="color: #ffffff;font-size: 20px;font-weight: 700">正在提交本次操作，请勿进行任何操作......</span>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInUp">
    <span id="gloUrl" style="display: none"></span>

    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title" style="height: 55px;">
                    <h5>所有记录</h5>

                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">

                        <div class="col-md-11 form-inline">
                            <div class="input-group col-xs-5">
                                <input class="input-sm form-control" id="searchKey" placeholder="请根据 用户昵称 进行关键词匹配"
                                       type="text">
                            </div>

                            <div class="input-group">
                                <button class="btn btn-sm btn-primary" id="getByKeywords"
                                        type="button">搜索
                                </button>
                            </div>
                        </div>
                    </div>
                    <!--            列表          -->
                    <div class="project-list">
                        <table class="table table-hover">
                            <tbody id="listBody"></tbody>
                        </table>
                    </div>
                    <!--                        页码控制-->
                    <div ajaxUrl="www.baidu.com" currentPage="1" id="pageHelper">
                        <div class="pageBottom col-xs-10 col-xs-offset-1" style="margin-top: 20px">
                            <nav aria-label="...">
                                <ul class="pager">
                                    <li class="previous disabled"><a href="javascript:void(0)"><span aria-hidden="true">&larr;</span>
                                        上一页</a></li>
                                    <li>
                                        <span>共</span>
                                        <span id="data_total">${total}</span>
                                        <span>条数据</span>
                                    </li>
                                    <li class="next"><a href="javascript:void(0)">下一页 <span
                                            aria-hidden="true">&rarr;</span></a></li>
                                </ul>
                            </nav>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<!--弹出框-->
<!--<div aria-hidden="true" class="modal inmodal" id="myModal" role="dialog" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="min-height: 400px;overflow-y: scroll">
            <div class="modal-header">
                <button class="close" data-dismiss="modal" type="button">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <i class="fa fa-users modal-icon" style="font-size: 60px"></i>
                <h4 class="modal-title">编辑用户</h4>

            </div>
            <div class="formListAdd">
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label>用户昵称</label>
                        <input class="form-control" id="userName" placeholder="输入用户昵称" type="text"></div>
                </div>
                <div class="modal-body addList">

                    <div class="form-group col-xs-12">
                        <label>用户账号</label>
                        <input class="form-control" id="account" placeholder="输入用户账号" type="text"></div>
                </div>
                <div class="modal-body addList">

                    <div class="form-group col-xs-12">
                        <label>密码</label>
                        <input class="form-control" id="password" placeholder="输入密码" type="text"></div>
                </div>


                <div class="modal-footer">
                    <button class="btn btn-white" data-dismiss="modal" type="button">关闭</button>
                    <button class="btn btn-success" data-dismiss="modal" id="confirmEdit" type="button">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>-->
<!-- 全局js -->
<script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- Sweet alert -->
<script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>

<!-- 自定义js -->
<script src="/static/hAdmin/js/content.js?v=1.0.0"></script>
<!--    分页js -->
<!--<script src="/static/wmmJs/public/PageHelper.js"></script>-->
<script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
<script src="/static/js/GloJs.js"></script>
<script>


    $(function () {

        let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
        let Glo_user = localStorage.getItem("userId")
        let currentPage = $("#pageHelper").attr("currentPage");
        let id = ""

        function getUserList(num) {
            let total = 0;//总数
            let pageSize = 6;//每页条数
            let html_dom = $("#listBody")
            $("#pageHelper").attr("ajaxUrl", "/system/company")

            let searchKey = $("#searchKey").val()
            if (num === 1) {
                searchKey = ""
                $("#searchKey").val("")
            }
            setTimeout(function () {
                $.ajax({
                    url: Glo_BaseUrl + "/system/user/list",
                    type: "get",
                    data: {
                        "pageSize": pageSize,
                        "pageNum": currentPage,
                        "searchKey": searchKey,

                    },
                    success: function (data) {

                        let ListStr = ''
                        total = data.total
                        let specialBtn = ``


                        for (let i = 0; i < data.list.length; i++) {
                            let item = data.list[i]
                            if (item.status === '1') {
                                specialBtn = `
                                <button class="btn btn-sm btn-danger stopBtn" thisId="${item.id}" title="停用"> <i class="fa fa-close"></i> </button>
                                `
                            }
                            if (item.status === '0') {
                                specialBtn = `
    <button class="btn btn-sm btn-success normalBtn" thisId="${item.id}" title="恢复"> <i class="fa fa-clock-o"></i> </button>
    `
                            }
                            if (item.status === '2') {
                                specialBtn = `
    <button class="btn btn-sm btn-info checkBtn" thisId="${item.id}" title="审核"> <i class="fa fa-check"></i> </button>
    `
                            }
                            ListStr +=
                                `<tr>
                                        <td class="project-title">
                                            <span > <strong>昵称： ${data.list[i].unickName}</strong> </span>
                                            <br/>
                                              <small>用户id：<span id="EventTime">${data.list[i].id}</span> </small>
                                        </td>
<td class="project-completion">
                                                <small>账号：<span id="dataForClass">${data.list[i].account}</span> </small>
                </td>
                                        <td class="project-completion">
                                                <small>创建时间：<span id="dataForClass">${data.list[i].createTime}</span> </small>

                </td>

                <td class="project-actions">
                <!-- <button class="btn btn-warning btn-sm seeRentDetail" title="编辑" id="seeRentDetail" data-toggle="modal" data-target="#myModal"
                 rentId="${data.list[i].id}"><i class="fa fa-edit"></i>  </button>-->
` + specialBtn + `

                                 </td>
                </tr>
                `

                        }

                        if (data.code !== 500) {
                            html_dom.html("")
                            html_dom.append(ListStr)
                        } else {
                            alert("获取失败")
                        }
                        total = data.total
                        $("#data_total").html(data.total);
                        //下一页
                        $('.next').unbind().click(function () {
                            if (currentPage * pageSize >= total) {
                                alert('已经是最后一页了')
                            } else {
                                currentPage++;
                                $("#pageHelper").attr("currentPage", currentPage);
                                if (currentPage > 0) {
                                    $(".previous").removeClass("disabled")
                                }
                                $(".project-list").addClass("animated bounceOutLeft")
                                setTimeout(function () {
                                    $(".project-list").removeClass("animated bounceOutLeft").addClass("animated bounceInRight")
                                }, 500)
                                getUserList(2)
                            }

                        });
                        //上一页
                        $('.previous').unbind().click(function () {
                            currentPage--;
                            $("#pageHelper").attr("currentPage", currentPage);
                            if (currentPage === 0) {
                                currentPage = 1;
                                $("#pageHelper").attr("currentPage", currentPage);
                                $(".previous").addClass("disabled");
                            } else {
                                $(".project-list").addClass("animated bounceOutRight")
                                setTimeout(function () {
                                    $(".project-list").removeClass("animated bounceOutRight bounceInRight").addClass("animated bounceInLeft")
                                }, 500)
                                getUserList(2)
                            }
                        });
                        //详情
                        $('.seeRentDetail').unbind().click(function () {
                          let  id = $(this).attr("rentId")
                            // console.log(id)
                            localStorage.setItem("id",id)
                            $.ajax({
                                url: Glo_BaseUrl + "/system/user/detail",
                                type: "get",
                                data: {
                                    "id": id
                                },
                                success: function (data) {
                                    $("#account").val(data.Data.account)
                                    $("#userName").val(data.Data.unickName)
                                    $("#password").val(data.Data.password)

                                },
                                error: function () {
                                    alert("服务器异常！network error！")
                                }
                            })
                        });

                        //停用
                        $(".stopBtn").unbind("click").click(function () {
                            let id = $(this).attr("thisId")
                            swal({
                                title: "您确定要停用账号？",
                                text: "停用可恢复！",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "停用",
                                closeOnConfirm: false
                            }, function () {
                                $.ajax({
                                    url: Glo_BaseUrl + "/system/user/edit",
                                    type: "post",
                                    data: {
                                        "userId": id,
                                        status: "0"
                                    },
                                    success: function (data) {
                                        if (data.code === 200) {
                                            swal("停用成功！", "您已经停用了此账号。", "success");
                                            getUserList()
                                        } else {
                                            swal("停用失败！", "停用失败。", "error");
                                        }

                                    },
                                    error: function () {
                                        alert("服务器异常！network error！")
                                    }
                                })
                            });
                        });
                        //恢复
                        $(".normalBtn").unbind("click").click(function () {
                            let id = $(this).attr("thisId")
                            swal({
                                title: "您确定要恢复该用户的账号？",
                                text: "",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#55dd67",
                                confirmButtonText: "恢复",
                                closeOnConfirm: false
                            }, function () {
                                $.ajax({
                                    url: Glo_BaseUrl + "/system/user/edit",
                                    type: "post",
                                    data: {
                                        "userId": id,
                                        status: "1"
                                    },
                                    success: function (data) {
                                        if (data.code === 200) {
                                            swal("恢复成功！", "您已经恢复了此账号。", "success");
                                            getUserList()
                                        } else {
                                            swal("恢复失败！", "恢复失败。", "error");
                                        }

                                    },
                                    error: function () {
                                        alert("服务器异常！network error！")
                                    }
                                })
                            });
                        });
                        //审核
                        $(".checkBtn").unbind("click").click(function () {
                            let id = $(this).attr("thisId")
                            swal({
                                title: "要审核通过此账号吗？",
                                text: "",
                                type: "warning",
                                showCancelButton: true,
                                confirmButtonColor: "#55c9dd",
                                confirmButtonText: "通过",
                                cancelButtonText: "我再想想",
                                closeOnConfirm: false
                            }, function () {
                                $.ajax({
                                    url: Glo_BaseUrl + "/system/user/edit",
                                    type: "post",
                                    data: {
                                        "userId": id,
                                        status: "1"
                                    },
                                    success: function (data) {
                                        if (data.code === 200) {
                                            swal("审核通过！", "审核通过", "success");
                                            getUserList()
                                        } else {
                                            swal("失败！", "失败。", "error");
                                        }

                                    },
                                    error: function () {
                                        alert("服务器异常！network error！")
                                    }
                                })
                            });
                        });
                    },
                    error: function () {
                        alert("服务器异常！network error！")
                    }
                });
            }, 300)


        }

        //确认编辑
        $("#confirmEdit").click(function () {
            $.ajax({
                url: Glo_BaseUrl + "/system/user/edit",
                type: "post",
                data: {
                    "userId": localStorage.getItem("id"),
                    uNickName: $("#userName").val(),
                    account: $("#account").val(),
                    password: $("#password").val(),
                },
                success: function (data) {
                    if (data.code === 200) {
                        swal(data.msg, "修改成功", "success");
                    } else {
                        swal(data.msg, "修改失败", "error");
                    }
                    getUserList()

                },
                error: function () {
                    alert("服务器异常！network error！")
                }
            })
        })

        //*******************************************
        getUserList(2)
        $("#getByKeywords").click(function () {
            getUserList(2)
        })
        $(".loading-example-btn").click(function () {
            getUserList(1)
        })


    })
</script>
</body>
</html>
